<template>
  <el-dialog v-model="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false" :close-on-press-escape="false">
    <el-form :model="dataForm" :rules="dataRule" ref="dataFormRef" @keyup.enter="dataFormSubmitHandle()" label-width="120px">
      <el-form-item label="主键" prop="id">
        <el-input v-model="dataForm.id" placeholder="主键"></el-input>
      </el-form-item>
      <el-form-item label="手机号" prop="mobile">
        <el-input v-model="dataForm.mobile" placeholder="手机号"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input v-model="dataForm.password" placeholder="密码"></el-input>
      </el-form-item>
      <el-form-item label="审核状态 -1失败 0审核中 1通过" prop="status">
        <el-input v-model="dataForm.status" placeholder="审核状态 -1失败 0审核中 1通过"></el-input>
      </el-form-item>
      <el-form-item label="会员类型 1采购商 2参展商 3搭建商" prop="type">
        <el-input v-model="dataForm.type" placeholder="会员类型 1采购商 2参展商 3搭建商"></el-input>
      </el-form-item>
      <el-form-item label="是否冻结 1是，0否" prop="freeze">
        <el-input v-model="dataForm.freeze" placeholder="是否冻结 1是，0否"></el-input>
      </el-form-item>
      <el-form-item label="上次登录时间" prop="lastLoginTime">
        <el-input v-model="dataForm.lastLoginTime" placeholder="上次登录时间"></el-input>
      </el-form-item>
      <el-form-item label="上次登录IP" prop="lastLoginIp">
        <el-input v-model="dataForm.lastLoginIp" placeholder="上次登录IP"></el-input>
      </el-form-item>
      <el-form-item label="本次登录时间" prop="loginTime">
        <el-input v-model="dataForm.loginTime" placeholder="本次登录时间"></el-input>
      </el-form-item>
      <el-form-item label="本次登录IP" prop="loginIp">
        <el-input v-model="dataForm.loginIp" placeholder="本次登录IP"></el-input>
      </el-form-item>
      <el-form-item label="注册时间" prop="registerTime">
        <el-input v-model="dataForm.registerTime" placeholder="注册时间"></el-input>
      </el-form-item>
      <el-form-item label="微信openid" prop="openId">
        <el-input v-model="dataForm.openId" placeholder="微信openid"></el-input>
      </el-form-item>
      <el-form-item label="" prop="headImg">
        <el-input v-model="dataForm.headImg" placeholder=""></el-input>
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-button @click="visible = false">{{ $t("cancel") }}</el-button>
      <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t("confirm") }}</el-button>
    </template>
  </el-dialog>
</template>

<script lang="ts">
import { defineComponent, reactive } from "vue";
import baseService from "@/service/baseService";
import { useDebounce } from "@/utils/utils";
export default defineComponent({
  setup() {
    return reactive({
      visible: false,
      dataForm: {
        id: "",
        mobile: "",
        password: "",
        status: "",
        type: "",
        freeze: "",
        lastLoginTime: "",
        lastLoginIp: "",
        loginTime: "",
        loginIp: "",
        registerTime: "",
        openId: "",
        headImg: ""
      }
    });
  },
  computed: {
    dataRule() {
      return {};
    }
  },
  created() {
    this.dataFormSubmitHandle = useDebounce(this.dataFormSubmitHandle);
  },
  methods: {
    init() {
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataFormRef"].resetFields();
        if (this.dataForm.id) {
          this.getInfo();
        }
      });
    },
    // 获取信息
    getInfo() {
      baseService.get("/noc/taccount/" + this.dataForm.id).then((res) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg);
        }
        this.dataForm = res.data;
      });
    },
    // 表单提交
    dataFormSubmitHandle() {
      this.$refs["dataFormRef"].validate((valid: boolean) => {
        if (!valid) {
          return false;
        }
        (!this.dataForm.id ? baseService.post : baseService.put)("/noc/taccount", this.dataForm).then((res) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          this.$message({
            message: this.$t("prompt.success"),
            type: "success",
            duration: 500,
            onClose: () => {
              this.visible = false;
              this.$emit("refreshDataList");
            }
          });
        });
      });
    }
  }
});
</script>
